module.exports = app => {

    //挂载 express 路由
    const express = require("express");
    const router = express.Router({
        mergeParams: true //表示合并url参数
    });

    //引入模型
    const Holiday = require('./../models/Holiday.js');//离归校时间

    //创建离归校时间
    router.post('/holiday', async (req, res) => {
        console.log('---收到增加创建离归校时间请求---');
        console.log(req.body);
        const model = await Holiday.create(req.body);
        res.send(model);

    });

    //请求离归校时间全部信息
    router.get('/holiday', async (req, res) => {
        console.log('---请求离归校时间全部信息---');

        const items = await Holiday.find();
        res.send(items);

    });


    //请求离归校时间全部信息
    router.get('/holiday/:id', async (req, res) => {
        console.log('---根据id进行请求离归校时间信息---');

        const item = await Holiday.findById(req.params.id);
        res.send(item);

    });


    //根据id进行编辑离归校时间
    router.put('/holiday/:id', async (req, res) => {

        console.log('---根据id进行编辑离归校时间---');
        console.log(req.body);
        const model = await Holiday.findByIdAndUpdate(req.params.id, req.body);
        res.send(model);

    });

    //根据id进行删除离归校时间
    router.delete('/holiday/:id', async (req, res) => {

        console.log('---删除---');
        
        const model = await Holiday.findByIdAndDelete(req.params.id);
        res.send({
            success: true
        });
    });

    router.get('/nihao', async (req, res) => {

        res.send('nihao');
    });


    app.use('/admin/api', router);

}